define(function(require, exports){
	var $ = require("jquery");
	var pubjs = require('pubjs');
	var view = require('@base/view');
	var util = require('util');
	var dspUtil = require('dspUtil');

	var Base = view.container.extend({
		init:function(config){
			config = pubjs.conf(config, {
				'class': 'P-CustomDownloadUser',
				'url': 'adexchange/weight',
				'view_model': {
					'data': []
				}
			});

			this.$id = null;
			this.Super('init', arguments);
		}
		,afterBuild:function(){
			this.append(`
				<div ms-repeat-item="data" class="fl">
					<label class="userLabel">{{item.Name}} | {{item.UserId}}</label>
				</div>
				<div class="fl">
					<span class="" pub-name="add" pub-mod="@base/common/input.button"/>
				</div>
			`);

			this.buildFromTemplate({
				add: {
					value: LANG('选择')
					,'class': 'btn btn-default'
					,width: 60
					,height: 30
				}
			});
		}
		,onInputClick: function(ev) {
			var c = this.getConfig();
			switch (ev.name) {
				case 'add':
					this.showPop();
					break;
				default :
					return false;
			}
		}
		,showPop: function() {
			var self = this;
			var mod = self.$.pop;
			var ids = this.getValue();
			if(!mod) {
				this.createAsync('pop',"admin/messageManage/popwin/popwin.selectCustomerPopwin", {
					title: LANG('选择客户')
					,noFilter: true
					,height: 650
					,showSub: false
					,grid: {
						singleSelect: true,
						param: {
							mongoField: ['UserId', 'UserName', 'Type', 'ExchangeInfo', 'CategoryId']
						},
						'list':{
							'rowSelect': false,
							'scroll_size': 10
						}
					}
				},function(mod) {
					mod.setParam({"Depth": 0}).show().setData(ids);
				});
			}
			else {
				mod.show().setData(ids);
			}
		}
		,onSelectCustomer: function(ev) {
			var data = ev.param;
			// 已选则用户信息
			this.setData(data);
			this.fire('dataChange', data);
			return false;
		}
		,validate: function(data){
			var vm = this.vm.$;
			return true;
		}
		,getValue: function()
		{
			var self = this;
			return self.vm.getItem('data');
		}
		,getData: function(){
			var self = this
				,vm = self.vm.$;

			return vm.data;
		}
		,setData: function(v)
		{
			var self = this
				,vm = self.vm.$;

			vm.data = v || [];
			return this;
		}
		,reset: function(){
			this.vm.reset();
			return this;
		}
	});

	exports.base = Base;
});